#!/bin/bash

echo "🧪 测试 Jar Monitor API"
echo ""

BASE_URL="http://localhost:8080"

# 检查应用是否运行
echo "1️⃣ 健康检查..."
curl -s ${BASE_URL}/actuator/health | jq '.' || echo "失败"
echo ""

# 查询模拟器状态
echo "2️⃣ 查询模拟器状态..."
curl -s ${BASE_URL}/api/simulator/status | jq '.' || echo "失败"
echo ""

# 启用模拟
echo "3️⃣ 启用模拟..."
curl -s -X POST ${BASE_URL}/api/simulator/enable | jq '.' || echo "失败"
echo ""

# 等待几秒
echo "⏳ 等待 5 秒生成数据..."
sleep 5
echo ""

# 查看 Prometheus 指标
echo "4️⃣ 查看部分 Prometheus 指标..."
curl -s ${BASE_URL}/actuator/prometheus | grep "^business_" | head -20
echo ""

# 查询模拟器状态
echo "5️⃣ 再次查询状态..."
curl -s ${BASE_URL}/api/simulator/status | jq '.' || echo "失败"
echo ""

# 停用模拟
echo "6️⃣ 停用模拟..."
curl -s -X POST ${BASE_URL}/api/simulator/disable | jq '.' || echo "失败"
echo ""

echo "✅ 测试完成"
echo ""
echo "💡 提示:"
echo "   - 访问 Web 界面: ${BASE_URL}"
echo "   - 查看完整指标: ${BASE_URL}/actuator/prometheus"
echo "   - 查看应用日志观察模拟数据"
